package com.woniuxy.creditsystem.financialmag.controller;

import com.github.pagehelper.PageInfo;
import com.woniuxy.creditsystem.common.bean.PageRequest;
import com.woniuxy.creditsystem.common.bean.PlatServiceInfo;
import com.woniuxy.creditsystem.common.bean.ReturnMoneyInfo;
import com.woniuxy.creditsystem.common.bean.TableResult;
import com.woniuxy.creditsystem.financialmag.service.IReturnMoneyInfo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 * @author ：pengchufeng
 * @date ：Created in 2020/12/14
 * @description：回款信息controller
 */
@RequestMapping("/rminfo")
@RestController
public class ReturnMoneyController {

    @Resource
    private IReturnMoneyInfo returnMoneyInfoImpl;

    /**
     * 无条件查询所有回款信息
     * @return
     */
    @RequestMapping(value="/select",produces = {"application/json;charset=utf-8"})
    public TableResult<ReturnMoneyInfo> findAll(PageRequest request, ReturnMoneyInfo returnMoneyInfo){
        Integer sNum = request.getOffset();
        Integer lNum = request.getLimit();
        Integer pNum = request.getPageNum();
        if(sNum == null || sNum < 0){
            sNum = 0;
            request.setOffset(sNum);
        }
        if(lNum == null || lNum <= 0){
            lNum = 10;
            request.setLimit(lNum);
        }
        if(pNum == null || pNum < 0){
            pNum = 1;
            request.setPageNum(pNum);
        }
        PageInfo<ReturnMoneyInfo> pageInfo = returnMoneyInfoImpl.findAll(request,returnMoneyInfo);
        List<ReturnMoneyInfo> lp = pageInfo.getList();
        for(int i = 0;i < lp.size();i++){
            ReturnMoneyInfo p1 = lp.get(i);
            p1.setStrNum(""+p1.getDataNum()+"/"+p1.getPeriods());
            p1.setNewPrincipal(new DecimalFormat("0.00").format(p1.getPrincipal()));
            p1.setNewInterest(new DecimalFormat("0.00").format(p1.getInterest()));
            p1.setNewPI(new DecimalFormat("0.00").format(p1.getPenaltyInteres()));
            if(p1.getAlsoTime() != null){
                p1.setStrDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(p1.getAlsoTime()));
            }else{
                p1.setStrDate("暂无数据");
            }
            lp.set(i,p1);
        }
        return new TableResult<ReturnMoneyInfo>(pageInfo.getTotal(),pageInfo.getList());
    }

}
